package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.*;
import com.heima.media.entity.WmNews;
import com.heima.media.service.IAuditService;
import com.heima.media.vo.WmNewsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmNewsService;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author mcm
 * @since 2022-06-21
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
public class WmNewsController{

    @Autowired
    private IWmNewsService wmNewsService;


    /**
     * 媒体审核列表查询
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/findPageByName")
    public ResponseResult findPageByName(@RequestBody WmNewsDto wmNewsDto){
      return   wmNewsService.findPageByName(wmNewsDto);
    }

    /**
     * 媒体审核列表详情查询
     * @param id
     * @return
     */
    @GetMapping("/findNewsVoById/{id}")
    public ResponseResult<WmNewsVo> findNewsVoById(@PathVariable(value = "id") Integer id){
      return   wmNewsService.findNewsVoById(id);

    }

    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageDto newsPageDto){
      return   wmNewsService.listPage(newsPageDto);
    }

    /**
     *下架商品
     */
    @PostMapping("/down_or_up")
    public ResponseResult xiajia(@RequestBody DownDto dto){
      return   wmNewsService.xiajia(dto);
    }

    /**
     * 发布内容详情查看
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult listById(@PathVariable(value = "id")Integer id){
        WmNews byId = wmNewsService.getById(id);
        return  ResponseResult.okResult(byId);
    }


    /**
     * 发布文章
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDtoDto dto){
        return wmNewsService.submit(dto);
    }


    @GetMapping("/cha")
    public ResponseResult cha( WmNews wmNews){
        if (Objects.isNull(wmNews)|| StringUtils.isEmpty(wmNews.getTitle1())){
            return ResponseResult.errorResult(404,"空");
        }
       List<WmNews>list= wmNewsService.cha(wmNews);
       return ResponseResult.okResult(list);
    }
}
